home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 130_01.zip / B.C < prev    next >
Text File  |  1993-06-01  |  6KB  |  203 lines

  1. /*    B.C
  2.  
  3.     Version 1.1    23-Aug-80
  4.  
  5.     This program prints out a sorted directory listing similar
  6.     to that that would be produced by a combination of STAT and
  7.     LIST. It is a modification of BIGDIR.C (written by Richard
  8.     Damon) designed for a Heath/Zenith H8 or H89/Z89. It is
  9.     configured for an H8/DEC VT100 in a 3-drive CP/M 1.43
  10.     environment, but it may be easily re-configured by changing
  11.     the commented definitions. For example, to configure it for
  12.     an H8/H19(ANSI) in a 2-drive CP/M 1.42 or 1.43:
  13.  
  14.        1.    #define    EXIT_STRING      "\n\033G\033<"
  15.             ... GS .. \033< enters ANSI mode, strangely. ...
  16.        2.    #define    HEADER_IN_STRING  "
  17.        3.    #define    HEADER_OUT_STRING "\n\033q"
  18.        4.    #define    NO_OF_DRIVES      2
  19.        5.    #define    VERTICAL_LINE      '\140'
  20.  
  21.     protocol:
  22.  
  23.         A>B    sorted directory of logged drive
  24.         A>B X    sorted directory of drive X
  25.         A>B *    sorted directory of all drives
  26.  
  27.     To configure it for non-Heath systems, the block which reads
  28.     the directory will have to be changed to read the correct
  29.     track with the correct skew. For standard CP/M, make the
  30.     following changes in addition to any re-configuration:
  31.     
  32.        1.    #define    CAPACITY      241    
  33.        2.    #define    DIRECTORY_TRACK      2
  34.        3.    #define    SECTORS_PER_TRACK 26
  35.        4.    #define    SKEW          6
  36.  
  37.        5.    replace the 'switch(sector)' block
  38.         with:
  39.             if(sector==1) sector=2;
  40.  
  41.     To configure it for 4 drives, make the following changes:
  42.  
  43.        1.    #define    NO_OF_DRIVES      4
  44.  
  45.        2.    int index; (was 'char')
  46.  
  47.        3.    in the setup and sort directory block:
  48.            1) change 'C' to 'D'
  49.            2) add the following immediately above:
  50.             else if(index<NO_OF_EXTENTS*4)
  51.                directory[index].unused[1]='C';
  52. */
  53.  
  54. /* #include <b:stdef.c>
  55. #include <b:system.c> Included out by GS */
  56.  
  57. #define    ALL            '*'
  58. #define    CAPACITY        90
  59. #define    DIRECTORY_TRACK        3
  60. #define    ERASED            0xE5
  61. #define    EXIT_STRING        "\n\033G"          /* Not as recommended. */
  62. #define    FCB_LENGTH        32
  63. #define    HEADER_IN_STRING    "\n\033p\033F"
  64. #define    HEADER_OUT_STRING   "\n\033q"
  65. #define    LENGTH_OF_DIRECTORY 16
  66. #define NO_OF_DRIVES        3            /* drives in system */
  67. #define    NO_OF_EXTENTS        64
  68. #define    SECTORS_PER_TRACK   20
  69. #define    SKEW            8
  70. #define    VERTICAL_LINE        '\140'
  71.  
  72. #define    SETTRK            10
  73. #define    SETSEC            11
  74. #define    SETDMA            12
  75. #define    READ            13
  76. #define INTER_DISK        25    /* GS */
  77. #define SELECT_DISK        14  /* GS */
  78. #define RESET            '\0' /* GS */
  79. #define EOS            '\0' /* GS */
  80.  
  81. main(argc,argv)
  82. int argc;
  83. char *argv[];
  84. {
  85.     struct fcb {
  86.        char entry_type;
  87.        char name[11];
  88.        char extent;
  89.        char unused[2];
  90.        char records;
  91.        char diskmap[16];
  92.     } directory[NO_OF_EXTENTS*NO_OF_DRIVES];
  93.  
  94.     char drive,entries,extents,logged_drive,loop_index;
  95.     char index;            /* GS */ 
  96.     char number_of_records;
  97.     char sector,used,wildcard;
  98.     int comp();
  99.  
  100. /*    process argument             */
  101.  
  102.     logged_drive=bdos(INTER_DISK,0);
  103.     if((wildcard=**++argv)==ALL) loop_index=0;
  104.     else {
  105.        (argc==1) ? drive=logged_drive : drive=wildcard-'A';
  106.        bdos(SELECT_DISK,drive); loop_index=NO_OF_DRIVES-1;
  107.        wildcard=RESET;
  108.        }
  109.  
  110. /*    read directory                  */
  111.  
  112.     entries=RESET;
  113.     do {
  114.        if(wildcard) bdos(SELECT_DISK,loop_index);
  115.        sector=1; bios(SETTRK,DIRECTORY_TRACK);
  116.        index=RESET;
  117.        do {
  118.           bios(SETSEC,sector); bios(SETDMA,&directory[entries++*4]);
  119.           bios(READ); sector+=SKEW;
  120.           if (sector>SECTORS_PER_TRACK) sector-=SECTORS_PER_TRACK;
  121.           switch(sector) {
  122.              case 7:  sector=4; break;
  123.              case 2:  sector=3; break;
  124.              case 1:  sector=2;
  125.              }
  126.           } while (++index<LENGTH_OF_DIRECTORY);
  127.        } while (++loop_index!=NO_OF_DRIVES);
  128.  
  129. /*    setup and sort directory        */
  130.  
  131.     if(wildcard) {
  132.        index=RESET; entries=NO_OF_EXTENTS*NO_OF_DRIVES;
  133.        do {
  134.           if(directory[index].entry_type!=ERASED) {    
  135.              if(index<NO_OF_EXTENTS) directory[index].unused[1]='A';
  136.              else if(index<NO_OF_EXTENTS*2)
  137.             directory[index].unused[1]='B';
  138.              else directory[index].unused[1]='C';
  139.              }
  140.           } while (++index<entries);
  141.        }
  142.     else entries=NO_OF_EXTENTS;
  143.     qsort(directory,entries,FCB_LENGTH,comp);
  144.  
  145. /*    print listing header              */
  146.  
  147.     index=RESET; printf(HEADER_IN_STRING);
  148.     do {
  149.        printf("FILENAME.EXT    NR  K");
  150.        if(index==2) {
  151.           if(wildcard) printf("  :");
  152.           break;
  153.           }
  154.        wildcard ? printf("  :   ") : printf("   ");
  155.     } while (++index<3);
  156.     printf(HEADER_OUT_STRING);
  157.  
  158. /*    print out sorted directory         */
  159.  
  160.     index=used=RESET;
  161.     do {
  162.        switch(index%3) {
  163.           case 0: putchar('\n'); break;
  164.           case 1:
  165.           case 2: printf("%c ",VERTICAL_LINE);
  166.           }
  167.          drive=directory[index].unused[1];
  168.        extents=directory[index].extent;
  169.        number_of_records=directory[index].records;
  170.        directory[index].unused[0]=EOS; loop_index=10;
  171.        do {
  172.           directory[index].name[loop_index+1]
  173.          =directory[index].name[loop_index];
  174.           } while (--loop_index>7);
  175.        directory[index].name[8]='.'; used+=(number_of_records+7)/8;
  176.        printf("%s",directory[index].name);
  177.        extents ? printf("+%d",extents) : printf("  ");
  178.        printf(" %3d %2d ",number_of_records,(number_of_records+7)/8);
  179.        if(wildcard) printf(" %c ",drive);
  180.        } while (!directory[++index].entry_type);
  181.  
  182. /*    print tail,select original drive    */
  183.  
  184.     printf(EXIT_STRING);
  185.     if (!wildcard) printf("\nfree: %dK\n",CAPACITY-used);
  186.     bdos(SELECT_DISK,logged_drive);
  187. }
  188.  
  189. /*    comparison function for 'qsort'        */
  190.  
  191. comp(x,y)
  192. char *x,*y;
  193. {
  194.     char index;
  195.     
  196.     for(index=1;(index||*x)&&*x!=ERASED&&*x==*y;
  197.        x++,y++,index=RESET);
  198.     if(*x>*y) return  1; if(*x<*y) return -1; return 0;
  199. }
  200. AL_LINE);
  201.           }
  202.          drive=directory[index].unused[1];
  203.        exten